package sprites;

import controlador.GestorDeDibuix;
import java.awt.Point;
import java.util.Observable;
import java.util.Observer;
import model.ModelJoc;

/**
 *
 * @author Carlos Moya Martinez
 */
public class GimberBoy extends Player implements Observer {
    private int bulletCount = 0;
    
    public GimberBoy(Point pantalla) {
        super((int) 3, false, pantalla);
        this.yMovementLimit = ((int) this.pantalla.getY() / 3) * 2;
        this.x = this.randInRangeInc(0, (int) this.pantalla.getX());
        this.y = this.randInRangeInc(yMovementLimit, (int) this.pantalla.getY());
        this.dimX = 64;
        this.dimY = 64;
        this.enemic = false;
    }

    @Override
    public void shoot() {
        Bullet bullet = new Bullet(this.x, this.y, this.pantalla);
        ModelJoc gm = ModelJoc.getInstancia();
        gm.afegirElement(bullet);
        this.bulletCount ++;
        
    }

    @Override
    public void animar() {
        /** TO DO **/
    }

    public int getBulletCount() {
        return bulletCount;
    }
    
    @Override
    public void setX(int x) {
        if (x < (this.dimX/2)) {
            super.setX(this.dimX/2);
        } else if (x > (pantalla.getX()-(this.dimX/2))) {
            super.setX((int)pantalla.getX()-(this.dimX/2));
        } else {
            super.setX(x);
        }  
    }   
    
    @Override
    public void setY(int y) {
        if (y > pantalla.getY()-(this.dimY/2)) {
            super.setY((int)pantalla.getY()-(this.dimY/2));    
        } else if (y < this.yMovementLimit+(this.dimY/2)) {
            super.setY(this.yMovementLimit+(this.dimY/2));
        } else {
            super.setY(y); 
        }
    }
    
    @Override
    public void pintar() {
        GestorDeDibuix.getInstancia().pintar("SPACESHIP", getX() - (dimX / 2), getY() - (dimY / 2), dimX, dimY);
    }

    private int randInRangeInc(int min, int max) {
        return min + (int) (Math.random() * (max - min));
    }

    public void update(Observable o, Object arg) {
        
    }
}
